package top.syfy.spb.upload.imageandwatermark.constant;

/**
 * 请求响应的状态码及响应信息的枚举类
 *
 * @author awg
 * @date 2020/10/23 星期五
 */
@SuppressWarnings({"unused"})
public enum ContentReturnEnum {

    UNDEFINE_EXCEPTION(-1, "未定义的错误"),
    CONTINUE(100, "继续"),
    SUCCESS(200, "成功"),
    UNAUTHORIZED(401, "未授权"),
    PAYMENT_REQUIRED(402, "需付费"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "无法找到"),
    METHOD_NOT_ALLOWED(405, "方法不被允许"),
    NOT_ACCEPTABLE(406, "无法接受"),
    REQUEST_TIMEOUT(408, "请求超时"),
    CONFLICT(409, "指令冲突"),
    REQUEST_ENTITY_TOO_LARGE(413, "请求实体过大"),
    REQUEST_URL_TOO_LONG(414, "所请求的URL地址过长"),
    REQUESTED_RANGE_NOT_SATISFIABLE(416, "请求的范围无法被满足"),
    EXPECTATION_FAILED(417, "预期内容错误"),
    UPGRADE_REQUIRED(426, "需升级"),
    TOO_MANY_REQUESTS(429, "请求数过多"),
    REQUEST_HEADERS_FIELDS_TOO_LARGE(431, "请求的头字段过大"),
    BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS(450, "已被Windows家长控制程序屏蔽"),
    INTERNAL_SERVER_ERROR(500, "内部服务器错误"),
    INSUFFICIENT_STORAGE(507, "存量不足"),
    NETWORK_CONNECT_TIMEOUT(599, "网络连接超时"),

    ILLEGAL_IMAGE(10001, "非法的图片: 请上传合法的格式的图片"),
    ILLEGAL_IMAGE_SIZE(10002, "上传的图片大小不合法")
    ;

    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String msg;

    ContentReturnEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 根据状态码获取其对应的[请求响应的状态码及响应信息的枚举类]
     *
     * @param code 状态码
     * @return 与状态码获取其对应的[请求响应的状态码及响应信息的枚举类]
     */
    public static ContentReturnEnum getContentReturnEnumByCode(Integer code) {
        for (ContentReturnEnum item : ContentReturnEnum.values()) {
            if (code.intValue() == item.getCode().intValue()) {
                return item;
            }
        }
        return null;
    }

}
